package com.code.springbootrocketmq.rocketmq;

import com.aliyun.openservices.ons.api.*;

import java.util.Properties;

/**
 * @author: liyufei
 * @date: 2020-02-15 20:54
 */
public class ConsumerTest {

    public static void main(String[] args) {
        Properties properties = new Properties();
        // 您在控制台创建的 Group ID
        properties.put(PropertyKeyConst.GROUP_ID, "GID-sku-change");
        // 鉴权用 AccessKeyId，在阿里云服务器管理控制台创建
        properties.put(PropertyKeyConst.AccessKey, "LTAI4FwU3q9TQGsDv9L3jMzo");
        // 鉴权用 AccessKeySecret，在阿里云服务器管理控制台创建
        properties.put(PropertyKeyConst.SecretKey, "oEjlRcpW99UdOZFafnBgjMZRP3zdKJ");
        // 设置 TCP 接入域名，进入控制台的实例详情页面，在页面上方选择实例后，在实例信息中的“获取接入点信息”区域查看
        properties.put(PropertyKeyConst.NAMESRV_ADDR, "http://MQ_INST_1009974337095810_BcFuGNC8.mq-internet-access.mq-internet.aliyuncs.com:80");

        Consumer consumer = ONSFactory.createConsumer(properties);
        consumer.subscribe("sku_change", "tagB", new MessageListener() {
            @Override
            public Action consume(Message message, ConsumeContext consumeContext) {
                System.out.println("Receive: " + new String(message.getBody()));
                return Action.CommitMessage;
            }
        });

        consumer.start();
        System.out.println("Consumer Started...");

    }
}
